package schedule;

import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import tags.PortalTagManager;

import com.ibatis.sqlmap.client.SqlMapClient;

import comm.util.SoptHashMap;
import comm.util.SqlMapLoader;

public class JobSetTags implements Job{
	private SqlMapClient sqlMapper = SqlMapLoader.getInstance(); 
	static Logger log = Logger.getLogger(JobSetTags.class);
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		setTodayTags();
	}
	
	public void setTodayTags(){
		log.debug("SET TODAY TAGS DOIT!!!!!!!!!!!!!");
		PortalTagManager portalTagsManager = new PortalTagManager();
		ArrayList lt = portalTagsManager.getCurrentIssueMixedKeyword();
		for (int i = 0; i < lt.size(); i++) {
			SoptHashMap curIssue = (SoptHashMap)lt.get(i);
			log.debug("CURRENT ISSUE KEYWORD INNED["+i+"] :"+curIssue.get("K").toString());
			Object curText = curIssue.get("K");
			if(curText!=null && curText.toString().length()>0){
				try {
					if(Integer.parseInt(sqlMapper.queryForObject("tag.getExistTodayTag",curIssue.get("K").toString()).toString())==0)
						sqlMapper.insert("tag.regTag", curIssue.get("K").toString());
					else
						log.debug(" CURRENT ISSUE ALREADY INNED!!"+curIssue.get("K").toString());
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
